package com.niit.mall.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.mall.common.domain.dto.PageDTO;
import com.niit.mall.order.domain.dto.OrderItemDTO;
import com.niit.mall.order.domain.po.OrderItem;
import com.niit.mall.order.mapper.OrderItemMapper;
import com.niit.mall.order.service.IOrderItemService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @BelongsProject:pardo_mall_backendd
 * @BelongsPackage: com.niit.mall.order.service.impl
 * @Author: XihenXi
 * @CreateTime: 2025-06-17  16:52
 * @Description: TODO
 * @Version: 1.0
 */

@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements IOrderItemService {

    /**
     * 根据订单id查询订单项
     * @param id 订单id
     */
    @Override
    public List<OrderItemDTO> getByOrderId(Long id) {
        // 执行查询
        List<OrderItem> orderItemsList = lambdaQuery()
                .eq(OrderItem::getOrderId, id)
                .list();

        // 手动转换为 DTO 列表
        return orderItemsList.stream()
                .map(item -> {
                    OrderItemDTO dto = new OrderItemDTO();
                    dto.setProductId(item.getProductId());
                    dto.setProductPic(item.getProductPic());
                    dto.setProductQuantity(item.getProductQuantity());
                    dto.setProductPrice(item.getProductPrice());
                    return dto;
                })
                .collect(Collectors.toList());
    }
}
